package com.yulongtian.offers.day202208.day20220824;

/**
 * @author YulongTian
 * @date 2022/8/24 - 9:34
 */
public class Test01 {
    public static void main(String[] args) {

    }

    public int[] reversePrint(ListNode head) {
        if(head==null){
            return new int[]{};
        }
        ListNode head2 = head;
        head = head.next;

        head2.next = null;


        int len = 1;


        while (head != null) {
            ListNode temp = head;
            head = head.next;

            temp.next = head2;
            head2 = temp;
            len++;

        }

        int[] res = new int[len];
        int j = 0;
        while (head2 != null) {
            res[j++] = head2.val;
            head2 = head2.next;
        }
        return res;
    }

}


class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }
}
